/* Copyright 203-2115 AtomWare Technology Pty Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * The flowing information must be keep 
 * JodaTimeConverter.java
 * jackysoft-basic-core
 * 2013-1-9下午3:10:18
 * @author 屈甲康
 * QQ285799123
 * mailto:qujiakang@gmail.com
 */

package org.jackysoft.struts2.converter;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.util.StrutsTypeConverter;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormatter;

public class JodaTimeConverter extends StrutsTypeConverter {

	static final Log logger = LogFactory.getLog(JodaTimeConverter.class);
	static final DateTimeFormatter formatter = new DateTimeFormatter(null, null);
	@Override
	public Object convertFromString(Map arg0, String[] arg1, Class arg2) {
	    String dstr = arg1[0];
	    DateTime dt = DateTime.parse(dstr);
		return dt;
	}

	@Override
	public String convertToString(Map arg0, Object arg1) {
		DateTime dt  = (DateTime) arg1;
		return dt.toString();
	}

}
